<?php

/**
 * +------ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER * ---------+
 * +----------------------------------------------------------------------------+
 * | PHPKiisf - Keep It in Simple Framework					|
 * | Version 1.0								|
 * | Copyright (C) <2013>  Mario Cezzare <mcezzare@gmail.com>			|
 * | Blog: http://mcezzare.blogspot.com.br					|
 * |										|
 * | This program is part of PHPKiisf, and is free software: you can		|
 * | redistribute it and/or modify it under the terms of the GNU 		|
 * | General Public License as published by					|
 * | the Free Software Foundation, either version 3 of the License, or		|
 * | (at your option) any later version.					|					|
 * |										|									|
 * | This program is distributed in the hope that it will be useful,		|
 * | but WITHOUT ANY WARRANTY; without even the implied warranty of		|
 * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the		|
 * | GNU General Public License for more details.				|
 * | You should have received a copy of the GNU General Public License		|
 * | along with this program.  If not, see <http://www.gnu.org/licenses/>.	|
 * +----------------------------------------------------------------------------+
 * | Author : <Mario Cezzare Angelicola Chiodi> <mcezzare@gmail.com>		|
 * +----------------------------------------------------------------------------+
 * | Contributors								|
 * |										|
 * +----------------------------------------------------------------------------+
 *
 */
/**
 * @package	Main
 * @access	public
 * @since	2013-03-08
 * @see		.htaccess essential to dispatcher work nicely
 * @author	Mario Cezzare <mcezzare@gmail.com>
 */
require_once 'lib/init.php' ;

$dispatcher = new dispatcher() ;

/*
 * If set to true , a wrong GET will return a Exception 404 from http_server
 */
$dispatcher->__set( "_return_not_found" , true ) ;

/**
 * Framework config routes , DON'T REMOVE until is fully configured.
 */
/*  Basic , no params or methods */
$dispatcher->add_route( array( "GET" , "/?config/" , "phpkiisf_controller:display_config" ) ) ;

/*  Normal , a public param or method */
$dispatcher->add_route( array( "GET" , "/?config/db/" , "phpkiisf_controller:display_test_db_config" ) ) ;
$dispatcher->add_route( array( "GET" , "/?config/about/" , "phpkiisf_controller:display_about" ) ) ;
$dispatcher->add_route( array( "GET" , "/?config/test/" , "phpkiisf_controller:test_config" ) ) ;
$dispatcher->add_route( array( "GET" , "/?config/routes/" , "phpkiisf_controller:display_routes" ) ) ;

/* Triple slashes */
$dispatcher->add_route( array( "GET" , "/?config/test/novo/" , "phpkiisf_controller:test_novo" ) ) ;

/* Builder Section */
$dispatcher->add_route( array( "GET" , "/?builder/" , "phpkiisf_controller:display_builder" ) ) ;

$dispatcher->add_route( array( "GET" , "/?builder/uml/" , "phpkiisf_controller:display_prepare_uml" ) ) ;




/**
 * End of Framework config routes , DON'T REMOVE until is fully configured.
 */
/**
 * Examples Section
 */
$dispatcher->add_route( array( "GET" , "/?examples/" , "example_controller:display_index" ) ) ;
$dispatcher->add_route( array( "GET" , "/?examples/boilerplate/" , "example_controller:display_boilerplate_examples" ) ) ;
$dispatcher->add_route( array( "GET" , "/?examples/php/" , "example_controller:display_php_examples" ) ) ;

$dispatcher->add_route( array( "GET" , "/?docs/" , "phpkiisf_controller:display_index" ) ) ;
/**
 * End Examples
 * Home, initial. The only value that dont fininsh with  a slash /
 * Adjust to your needs
 */
$dispatcher->add_route( array( "GET" , "/?" , "home_controller:display_index" ) ) ;

/**
 * Sections
 *
 * Add here your routes, Maybe it cames from database
 */
$dispatcher->add_route( array( "GET" , "/?produtos/" , "product_controller:display_index" ) ) ;



/* End of routes   */

//var_dump( $dispatcher ) ;

/* Call dispatcher */
try {
	if ( !$dispatcher->exec() ) {
		var_dump( $dispatcher->_errors ) ;
		throw new Exception( "ROUTE NOT FOUND" , 404 ) ; // get your kicks .. on route 66 .:)
	}
}
catch ( Exception $E ) {
	/*
	 * @TODO: fazer um template ou adicionar uma rota
	 * para uma página como o 404 da uol por exemplo
	 */
	display_user_message( $E->getMessage() ) ;
}


/**
 *  Start Tests
 *
 * All sections can be putted in a route
 * Basic methods from crud You can create public methods new, edit, save, back, etc..
 */
/*  Basic , no params or methods */
//$dispatcher->add_route( array( "GET" , "/?test" , "phpkiisf_controller:test_config" ) ) ;

/*  Normal , a public param or method */
//$dispatcher->add_route( array( "GET" , "/?test/new/" , "default_controller:display_test_new" ) ) ;
//$dispatcher->add_route( array( "GET" , "/?test/edit/" , "default_controller:display_test_edit" ) ) ;
//$dispatcher->add_route( array( "GET" , "/?test/list/" , "default_controller:display_test_new" ) ) ;
//$dispatcher->add_route( array( "POST" , "/?test/save/" , "default_controller:function_save" ) ) ;
//$dispatcher->add_route( array( "POST" , "/?test/remove/" , "default_controller:function_remove" ) ) ;

/* Wrong method in a right route , test to see --> /test/wrong/a
 * $dispatcher->add_route( array( "GET" , "/?test/wrong/" , "default_controller:display_wrongdahkd" ) ) ;
 */

/**
 *  End Tests
 */
?>